package com.imedway.ihe.dtz.atna;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class UDPServer {

   public static void main(String[] args) throws Throwable {
      DatagramSocket datagramSocket = new DatagramSocket(8088);
      while (true) {
         DatagramPacket packet = new DatagramPacket(new byte[512], 512);
         try {
            datagramSocket.receive(packet);
            String msg = new String(packet.getData(), 0, packet.getLength());
            System.out.println(packet.getAddress() + "/" + packet.getPort() + ":" + msg);
            packet.setData("I am server!!!".getBytes());
            datagramSocket.send(packet);
         } catch (Exception e) {
            e.printStackTrace();
         }
      }
   }
}